#include "net/TcpServer.h"
#include "net/EventLoop.h"
#include "net/Channel.h"
#include "Base/Logger.h"
#include "Base/Buffer.h"
#include "net/TcpConnection.h"

using namespace toym;
using namespace toym::net;

void onMessage(const TcpConnectionPtr& conn, Buffer* buf, Timestamp ts) {
    std::string msg = buf->readAsString();
    LOG_INFO << "onMessage: " << msg;
    conn->send(msg);
}

int main() {

    LogPuter::setLevel(LogPuter::LogLevel::INFO);

    EventLoop loop;
    InetAddress addr(10077);
    TcpServer server(&loop, addr);
    server.setThreadNum(2);
    server.setMessageCallback(onMessage);
    server.start();

    loop.loop();
}